package com.ruoyi.tbm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tbm.domain.TbmEquipment;
import com.ruoyi.tbm.service.ITbmEquipmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 盾构机配件Controller
 * 
 * @author ruoyi
 * @date 2022-07-13
 */
@RestController
@RequestMapping("/tbm/equipment")
public class TbmEquipmentController extends BaseController
{
    @Autowired
    private ITbmEquipmentService tbmEquipmentService;

    /**
     * 查询盾构机配件列表
     */
    @PreAuthorize("@ss.hasPermi('tbm:equipment:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbmEquipment tbmEquipment)
    {
        startPage();
        List<TbmEquipment> list = tbmEquipmentService.selectTbmEquipmentList(tbmEquipment);
        return getDataTable(list);
    }

    /**
     * 导出盾构机配件列表
     */
    @PreAuthorize("@ss.hasPermi('tbm:equipment:export')")
    @Log(title = "盾构机配件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbmEquipment tbmEquipment)
    {
        List<TbmEquipment> list = tbmEquipmentService.selectTbmEquipmentList(tbmEquipment);
        ExcelUtil<TbmEquipment> util = new ExcelUtil<TbmEquipment>(TbmEquipment.class);
        util.exportExcel(response, list, "盾构机配件数据");
    }

    /**
     * 获取盾构机配件详细信息
     */
    @PreAuthorize("@ss.hasPermi('tbm:equipment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(tbmEquipmentService.selectTbmEquipmentById(id));
    }

    /**
     * 新增盾构机配件
     */
    @PreAuthorize("@ss.hasPermi('tbm:equipment:add')")
    @Log(title = "盾构机配件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbmEquipment tbmEquipment)
    {
        return toAjax(tbmEquipmentService.insertTbmEquipment(tbmEquipment));
    }

    /**
     * 修改盾构机配件
     */
    @PreAuthorize("@ss.hasPermi('tbm:equipment:edit')")
    @Log(title = "盾构机配件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbmEquipment tbmEquipment)
    {
        return toAjax(tbmEquipmentService.updateTbmEquipment(tbmEquipment));
    }

    /**
     * 删除盾构机配件
     */
    @PreAuthorize("@ss.hasPermi('tbm:equipment:remove')")
    @Log(title = "盾构机配件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(tbmEquipmentService.deleteTbmEquipmentByIds(ids));
    }
}
